<template>
  <div>
    <!-- 
          data:表格的数据
          default-expand-all：默认展开所有
          :tree-props="{ children: 'children' }" 判断是否有子节点的字段
          sortable：自动排序
       -->
    <el-table
      :data="arr"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      :tree-props="{ children: 'children' }"
    >
      <el-table-column prop="id" label="角色编号" sortable width="180">
      </el-table-column>
      <el-table-column prop="rolename" label="角色名称" sortable >
      </el-table-column>
     
      <el-table-column label="状态" sortable >
        <!-- 作用域插槽 -->
        <template slot-scope="scope">
          <el-button v-if="scope.row.status == 1" type="primary"
            >启用</el-button
          >
          <el-button v-else type="info">禁用</el-button>
        </template>
      </el-table-column>

      <el-table-column prop="name" label="操作" sortable >
        <!-- 作用域插槽 -->
        <template slot-scope="scope">
          <el-button type="primary" @click="willupdate(scope.row.id)">编辑</el-button>
          <el-button type="danger" @click="del(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>

      <!-- <el-table-column prop="sex" label="性别" sortable width="180">
        作用域插槽
        <template slot-scope="scope">
          {{ scope.row.sex == 1 ? "男" : "女" }}
        </template>
      </el-table-column> -->
    </el-table>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import { reqroledelete } from '../../../../../../day12/code/u_back/src/http/api';
import { successAlert } from '../../../../../../day12/code/u_back/src/utils/alert';
export default {
  props: ["arr"],
  data() {
    return {
    
    };
  },
  computed: {
    ...mapGetters({}),
  },
  mounted() {},
  methods: {
    ...mapActions({}),
    // 5.点了编辑
    willupdate(id){
        this.$emit("willupdate",id)
    },
    // 7.点了删除
    del(id){
       this.$confirm('你确定要删除吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(() => {
          // 点击删除
          reqroledelete({id:id}).then(res=>{
            if(res.data.code==200){

              successAlert(res.data.msg)
              // 通知父组件刷新列表
              this.$emit("init")
            }
          })
        }).catch(()=>{

        })
    }
  },
};
</script>
<style scoped lang="less">
@import "../../../less/index.less";
</style>